home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / Feelin021015 / Examples / 03.c < prev    next >
C/C++ Source or Header  |  2002-10-28  |  8KB  |  224 lines

  1. #include <stdlib.h>
  2.  
  3. #include <intuition/intuition.h>
  4. #include <libraries/feelin.h>
  5. #include <clib/utility_protos.h>
  6. #include <clib/feelin_protos.h>
  7.  
  8. struct FeelinBase    *FeelinBase;
  9. struct UtilityBase   *UtilityBase;
  10.  
  11. /// OBJ
  12. struct LocalObjectData {
  13.    BYTE           Mode;
  14.    BYTE           Way;
  15. };
  16.  
  17. #define FA_CrazyGauge_Mode    FCCA_BASE
  18.  
  19. long enum {
  20.    FV_CrazyGauge_More,
  21.    FV_CrazyGauge_Less,
  22.    FV_CrazyGauge_TwoWays,
  23.    FV_CrazyGauge_Crary
  24. };
  25. //+
  26.  
  27. ///mNew
  28. __saveds ULONG mNew(struct FeelinClass *cl, struct FeelinObject *obj,struct LocalObjectData *lod,ULONG *args)
  29. {
  30.    if (F_SuperDoA(cl,obj,FM_New,args))
  31.    {
  32.       lod->Mode = GetTagData(FA_CrazyGauge_Mode,FV_CrazyGauge_More,(struct TagItem *)args);
  33.       lod->Way  = TRUE;
  34.  
  35.       return (ULONG) obj;
  36.    }
  37.  
  38.    return NULL;
  39. }
  40. //+
  41. ///mHandleEvent
  42. __saveds ULONG mHandleEvent(struct FeelinObject *obj,struct LocalObjectData *lod,struct FS_HandleEvent *he)
  43. {
  44.    ULONG val,max,min;
  45.  
  46.    if (he->Msg->Class == IDCMP_INTUITICKS)
  47.    {
  48.       F_Do(obj,FM_Get,
  49.                FA_Numeric_Value,  &val,
  50.                FA_Numeric_Max,    &max,
  51.                FA_Numeric_Min,    &min, NULL);
  52.  
  53.       switch (lod->Mode)
  54.       {
  55.          case FV_CrazyGauge_More:
  56.             F_Set(obj,FA_Numeric_Value,(val == max) ? min : (val + 1));
  57.             break;
  58.          case FV_CrazyGauge_Less:
  59.             F_Set(obj,FA_Numeric_Value,(val == min) ? max : (val - 1));
  60.             break;
  61.          case FV_CrazyGauge_TwoWays:
  62.             if (lod->Way)
  63.             {
  64.                if (val == max)
  65.                {
  66.                   lod->Way = FALSE;
  67.                } else {
  68.                   F_Set(obj,FA_Numeric_Value,val + 1);
  69.                }
  70.             }
  71.             else
  72.             {
  73.                if (val == min)
  74.                {
  75.                   lod->Way = TRUE;
  76.                } else {
  77.                   F_Set(obj,FA_Numeric_Value,val - 1);
  78.                }
  79.             }
  80.             break;
  81.          case FV_CrazyGauge_Crary:
  82.             srand(max);
  83.             F_Set(obj,FA_Numeric_Value,(ULONG)rand());
  84.             break;
  85.       }
  86.  
  87.       return NULL;
  88.    }
  89. }
  90. //+
  91. ///mDispatcher
  92. __asm __saveds ULONG mDispatcher(
  93.    register __a2 struct FeelinClass   *cl,
  94.    register __a0 struct FeelinObject  *obj,
  95.    register __d0 ULONG                 method,
  96.    register __a1 ULONG                *args)
  97. {
  98.    struct LocalObjectData *lod = INST_DATA(cl,obj);
  99.  
  100.    switch (method)
  101.    {
  102.       case FM_New:         return mNew(cl,obj,lod,args);
  103.       case FM_Show:               F_Do(obj,FM_ModifyHandler,IDCMP_INTUITICKS,NULL); return NULL;
  104.       case FM_Hide:               F_Do(obj,FM_ModifyHandler,NULL,IDCMP_INTUITICKS); return NULL;
  105.       case FM_HandleEvent: return mHandleEvent(obj,lod,(struct FS_HandleEvent *)args);
  106.       default:             return F_SuperDoA(cl,obj,method,args);
  107.    }
  108. }
  109. //+
  110.  
  111. ///Main
  112. void main()
  113. {
  114.    static struct FeelinClass *fcc;
  115.    static APTR c,w, g,b;
  116.  
  117.    if (FeelinBase = (struct FeelinBase *)OpenLibrary("feelin.library",FV_VERSION))
  118.    {
  119.       UtilityBase = FeelinBase->Utility;
  120.  
  121.       if (fcc = F_CreateClass(FA_SuperID,     FC_Gauge,
  122.                               FA_DataSize,    sizeof (struct LocalObjectData),
  123.                               FA_Dispatcher,  mDispatcher,
  124.                               NULL))
  125.       {
  126.          c = ClientObject,
  127.             FA_Pen_Shine,     "c:FFDCA0",
  128.             FA_Pen_Fill,      "c:AA7864",
  129.             FA_Pen_Highlight, "c:2A1E19",
  130.  
  131.             Child, w = WindowObject, FA_Window_Title,"Feelin : Gauges",
  132.                FA_Back, FI_Fill,
  133.  
  134.                Child, VGroup,
  135.                   Child, g = HGroup,
  136.                      Child, VGroup,
  137.                         Child, Gauge(TRUE,0,100,25),
  138.                         Child, Gauge(TRUE,0,100,50),
  139.                         Child, Gauge(TRUE,0,100,75),
  140.                         Child, Gauge(TRUE,0,100,100),
  141.                         Child, F_NewObj(fcc->ID,FA_Horizontal,      TRUE,
  142.                                                 FA_Frame,           FP_Frame_Gauge,
  143.                                                 DontChain,
  144.                                                 FA_Numeric_Max,     100,
  145.                                                 FA_CrazyGauge_Mode, FV_CrazyGauge_Crary,
  146.                                                 NULL),
  147.                      End,
  148.  
  149.                      Child, VBar,
  150.  
  151.                      Child, VGroup, FA_FixedHeight,TRUE,
  152.                         Child, F_NewObj(fcc->ID,FA_Horizontal,      TRUE,
  153.                                                 FA_Frame,           FP_Frame_Gauge,
  154.                                                 DontChain,
  155.                                                 FA_Numeric_Max,     100,
  156.                                                 FA_Numeric_Value,   0,
  157.                                                 FA_CrazyGauge_Mode, FV_CrazyGauge_TwoWays,
  158.                                                 NULL),
  159.  
  160.                         Child, F_NewObj(fcc->ID,FA_Horizontal,      TRUE,
  161.                                                 FA_Frame,           FP_Frame_Gauge,
  162.                                                 DontChain,
  163.                                                 FA_Numeric_Max,     100,
  164.                                                 FA_Numeric_Value,   100,
  165.                                                 FA_CrazyGauge_Mode, FV_CrazyGauge_TwoWays,
  166.                                                 NULL),
  167.  
  168.                         Child, F_NewObj(fcc->ID,FA_Horizontal,      TRUE,
  169.                                                 FA_Frame,           FP_Frame_Gauge,
  170.                                                 DontChain,
  171.                                                 FA_Numeric_Max,     100,
  172.                                                 FA_Numeric_Value,   0,
  173.                                                 FA_CrazyGauge_Mode, FV_CrazyGauge_TwoWays,
  174.                                                 NULL),
  175.  
  176.                         Child, F_NewObj(fcc->ID,FA_Horizontal,      TRUE,
  177.                                                 FA_Frame,           FP_Frame_Gauge,
  178.                                                 DontChain,
  179.                                                 FA_Numeric_Max,     100,
  180.                                                 FA_Numeric_Value,   100,
  181.                                                 FA_CrazyGauge_Mode, FV_CrazyGauge_TwoWays,
  182.                                                 NULL),
  183.                      End,
  184.                   End,
  185.  
  186.                   Child, b = TextObject,
  187.                      FA_InputMode,        FV_InputMode_Toggle,
  188.                      FA_Fixed,            TRUE,
  189.                      FA_Inner_Left,       6L,
  190.                      FA_Inner_Right,      6L,
  191.                      FA_Inner_Top,        3L,
  192.                      FA_Inner_Bottom,     3L,
  193.                      FA_Frame,            0x21,
  194.                      FA_AltFrame,         0x00,
  195.                      FA_Back,             FI_Fill,
  196.                      FA_AltBack,          FI_Dark,
  197.                      FA_Text,             "Toggle Gauges Look",
  198.                      FA_Text_PreParse,    "`Ss`Sh`<0>",
  199.                      FA_Text_AltPreParse, "`Sn`<1>",
  200.                      FA_Text_VCenter,     TRUE,
  201.                      End,
  202.                End,
  203.  
  204.                FA_Window_ActiveObject, b,
  205.             End,
  206.          End;
  207.  
  208.          if (c)
  209.          {
  210.             F_Do(b,FM_Notify,FA_Selected,FV_Notify_Always,g,5,FM_Set,FA_Gauge_Simple,FV_Notify_Value,FA_Group_Forward,TRUE);
  211.             F_Do(w,FM_Notify,FA_Window_CloseRequest,TRUE,FV_Notify_Client,2,FM_Client_ReturnID,FV_Client_Quit);
  212.             F_Set(w,FA_Window_Open,TRUE);
  213.  
  214.             F_DoA(c,FM_Client_Run,NULL);
  215.  
  216.             F_DisposeObj(c);
  217.          }
  218.          F_RemoveClass(fcc);
  219.       }
  220.       CloseLibrary((struct Library *) FeelinBase);
  221.    }
  222. }
  223. //+
  224.